import eslint from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import prettierConfig from "./prettier.config.mjs"; // 显式导入Prettier配置
import eslintPluginPrettier from "eslint-plugin-prettier";
import oxlint from "eslint-plugin-oxlint";

/**
 * ESLint 代码校验配置模块
 * @module ESLintConfig
 * @author 高顺鹏 <gaoshunpeng76@163.com>
 * @since 2025-05-26
 *
 * @see [ESLint 扁平化配置文档]{@link https://eslint.org/docs/latest/use/configure/configuration-files-new}
 * @see [TypeScript ESLint 配置]{@link https://typescript-eslint.io/getting-started}
 * @see [Vue ESLint 插件配置]{@link https://eslint.vuejs.org/guide/}
 */
export default tseslint.config(
  {
    ignores: ["node_modules", "dist", "public"],
  },

  /** js推荐配置 */
  eslint.configs.recommended,
  /** ts推荐配置 */
  ...tseslint.configs.recommended,
  ...oxlint.configs["flat/recommended"],
  /**
   * javascript 规则
   */
  {
    files: ["**/*.{js,mjs,cjs}"],
    rules: {
      "no-console": "warn",
    },
  },

  /**
   * 配置全局变量
   */
  {
    languageOptions: {
      globals: {
        ...globals.node,
        ...globals.jest,
      },
      sourceType: "commonjs",
      parserOptions: {
        projectService: {
          allowDefaultProject: ["*.mjs", "*.js"],
        },
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
  /**
   * typescript 规则
   */
  {
    files: ["**/*.{ts,tsx}"],
    rules: {
      "@typescript-eslint/no-explicit-any": "off",
      "@typescript-eslint/no-require-imports": "off",
    },
  },

  // 显式配置Prettier，关联配置文件
  {
    plugins: {
      prettier: eslintPluginPrettier,
    },
    rules: {
      "prettier/prettier": ["error", prettierConfig],
    },
  },
);
